from tencentcloud.common import credential
from tencentcloud.ft.v20200304 import ft_client, models
import os

class TencentAIService:
    def __init__(self):
        self.cred = credential.Credential(
            os.getenv("TENCENT_SECRET_ID"),
            os.getenv("TENCENT_SECRET_KEY")
        )
        self.client = ft_client.FtClient(self.cred, "ap-beijing")
    
    def generate_emoji(self, image_url):
        req = models.FaceCartoonPicRequest()
        req.Url = image_url
        resp = self.client.FaceCartoonPic(req)
        return resp.ResultUrl

# 在 emoji_controller.py 中使用
@ns.route('/generate')
class EmojiGenerator(Resource):
    def post(self):
        try:
            # ... 验证代码 ...
            
            # 使用腾讯云AI生成
            tencent_service = TencentAIService()
            result_url = tencent_service.generate_emoji(data['image_url'])
            
            # ... 保存结果代码 ... 